package com.team;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class TeamServlet extends HttpServlet {
	

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        String title = req.getParameter("title");
        String artist = req.getParameter("artist");
        HashMap <String, String> playlist = new HashMap<String, String>();
        playlist.put(title, artist);
        
        String partyname= req.getParameter("partyname");
        String location = req.getParameter("location");
        Date date = new Date();
        String hostName = req.getParameter("hostName");
        String hostPassword = req.getParameter("hostPassword");
        String guestPassword = req.getParameter("guestPassword");

        Party party = new Party(partyname, location, hostName, date, playlist, hostPassword, guestPassword);
        
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(party);
        } finally {
            pm.close();
        }

        resp.sendRedirect("/song.jsp");
    }
}
